home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / TERMIN.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  4KB  |  188 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet driver terminator version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1988-1992, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?
  44.  
  45. handle        dw    ?
  46.  
  47. bogus_type    db    0,0        ;totally bogus type code.
  48.  
  49. signature    db    'PKT DRVR',0
  50. signature_len    equ    $-signature
  51.  
  52. flagbyte    db    0
  53. S_OPTION    equ    8
  54.  
  55. usage_msg        db    "usage: termin <packet_int_no>",'$'
  56. no_signature_msg    db    "termin: no packet driver at that address",'$'
  57. ok_msg            db    "termin: terminate completed",'$'
  58.  
  59. usage_error:
  60.     mov    dx,offset usage_msg
  61. error:
  62.     mov    ah,9
  63.     int    21h
  64.     int    20h
  65.  
  66. start_1:
  67.     cld
  68.  
  69.     mov    dx,offset copyleft_msg
  70.     mov    ah,9
  71.     int    21h
  72.  
  73.     mov    si,offset phd_dioa+1
  74.     call    skip_blanks        ;end of line?
  75.     cmp    al,CR
  76.     je    usage_error
  77.  
  78. chk_options:
  79.     call   skip_blanks
  80.     cmp    al,'-'            ; any options?
  81.     je    more_opt
  82.     cmp    al,'/'
  83.     jne    no_more_opt
  84. more_opt:
  85.     inc    si            ; skip past option char
  86.     lodsb                ; read next char
  87.     or    al,20h            ; convert to lower case
  88.     cmp    al,'s'
  89.     jne    usage_error
  90.     or    flagbyte,S_OPTION
  91.     jmp    chk_options
  92. no_more_opt:
  93.  
  94.     mov    di,offset packet_int_no
  95.     call    get_number
  96.  
  97.     mov    ah,35h            ;get their packet interrupt.
  98.     mov    al,packet_int_no
  99.     int    21h
  100.     mov    their_isr.offs,bx
  101.     mov    their_isr.segm,es
  102.  
  103.     lea    di,3[bx]
  104.     mov    si,offset signature
  105.     mov    cx,signature_len
  106.     repe    cmpsb
  107.     jne    no_signature_err
  108.  
  109.     push    ds
  110.     mov    ax,1ffh            ;driver_info
  111.     int_pkt
  112.     pop    ds
  113.     call    fatal_error
  114.  
  115.     mov    ah,2            ;access_type
  116.     mov    al,ch            ;their class from driver_info().
  117.     mov    bx,dx            ;their type from driver_info().
  118.     mov    dl,cl            ;their number from driver_info().
  119.     mov    cx,2            ;use type length 2.
  120.     mov    si,offset bogus_type
  121.     push    cs            ;es:di -> our receiver.
  122.     pop    es
  123.     mov    di,offset our_recv
  124.     int_pkt
  125.     call    fatal_error
  126.     mov    handle,ax
  127.  
  128.     test    flagbyte,S_OPTION
  129.     jz    not_stop
  130.     mov    ah,8            ; f_stop
  131.     int_pkt
  132.     jmp    now_done
  133. not_stop:
  134.  
  135.  
  136.     mov    ah,5            ;terminate the driver.
  137.     mov    bx,handle
  138.     int_pkt
  139.     jnc    now_close
  140.     call    print_error
  141. now_close:
  142.     mov    ah,3            ;release_type
  143.     mov    bx,handle
  144.     int_pkt
  145.     jnc    now_done        ;if ok, we're done.
  146.     cmp    dh,BAD_HANDLE        ;if it succeeded, we'll get a bad handle.
  147.     je    now_done        ;it worked.
  148.     stc
  149.     call    fatal_error
  150.     int    20h
  151. now_done:
  152.         push    cs
  153.         pop     ds
  154.         lea     dx,ok_msg
  155.         mov     ah,9
  156.         int     21h
  157.         int     20h
  158.  
  159.  
  160. our_recv:
  161.     or    ax,ax            ;first or second call?
  162.     jne    our_recv_1        ;second -- we ignore the packet
  163.     push    cs
  164.     pop    es
  165.     mov    di,offset our_buffer
  166. our_recv_1:
  167.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  168.  
  169.  
  170. no_signature_err:
  171.     mov    dx,offset no_signature_msg
  172.     mov    ah,9
  173.     int    21h
  174.     int    20h
  175.  
  176.  
  177.     include    pkterr.asm
  178.     include    getnum.asm
  179.     include    skipblk.asm
  180.     include    getdig.asm
  181.     include    chrout.asm
  182.  
  183. our_buffer    label    byte
  184.  
  185. code    ends
  186.  
  187.     end    start
  188.